package ace.states;

import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import ace.system.StateManager;

public class GameState {
	//State ID
	public static final int FRONT           = 0;
	public static final int LEVELS          = 1;
	public static final int GAME            = 2;
	public static final int CREDITS         = 5;
	public static final int SPLASH          = 6;
	public static final int HELP            = 7;
	public static final int LOADING         = 8;
	public static final int CREATE_PROFILE  = 10;
	public static final int PROFILE         = 11;
	public static final int MENU            = 12;
	public static final int GARAGE_MENU     = 13;

	public GameState(int id) {
		//No background
		this(id, (String)null);
		mKeysHoldable = false;
	}
	
	public GameState(int id, Image background) {
		//Default
		this(id, (String)null);
		
		//Set background
		m_Background = background;
	}

	public GameState(int id, String background) {
		//Initialize variable
		m_ID			= id;
		m_Active		= false;
		m_Background	= null;
        m_Colors        = null;

		//Load background if exist
		if (background != null) {
			try {
				m_Background = Image.createImage(background);
			} catch (IOException ex) {}
		}
	}
	

	public void initialize() {
		//Set active
		m_Active = true;
	}

	//Accessors
	public int getID()				{	return m_ID;			}
	public boolean isActive()		{	return m_Active;		}
	public boolean isKeyHoldable()	{	return mKeysHoldable;	}

	public void onEnter() {}
	public void onExit() {}
	public void onRemove() {}
	public void onPause() {}
	public void onResume() {}
	public void keyPressed(int key) {}
	public void update(long time, int keys) {}
	
	public void draw(Graphics g) {
		//Defaulting to black
		g.setColor(0x000000);

		//Draw background if exist
		if (m_Background != null)	g.drawImage(m_Background, 0, 0, Graphics.LEFT | Graphics.TOP);
		else						g.fillRect(0, 0, StateManager.instance().getWidth(), StateManager.instance().getHeight());
	}

	//Members
	protected int		m_ID;
	protected boolean	m_Active;
	protected Image		m_Background;
    protected int[]     m_Colors;

	protected boolean	mKeysHoldable;
}
